<?php

/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends PsController
{
	public $_apiKey;
	public $_agency;


	/**
	 * Default admin controller filter.
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl',
			'domainName',
		);
	}
	
	public function filterDomainName ($filterChain) {
		$url = Yii::app()->request->hostInfo;
		$domainName = parse_url($url, PHP_URL_HOST);

		if (strpos($domainName, 'propsage.com') === false) {
			$this->_apiKey = ApiKey::model()->findByAttributes(array(
				'domain_name' => $domainName
			));
			
			if ($this->_apiKey != null) {
				$this->_agency = $this->_apiKey->agency;
			}
		}

		$filterChain->run();
	}
}